package com.rw.tool.util.expression.expression.parser.element;

import com.rw.tool.util.expression.element.ExpressionElement;
import com.rw.tool.util.expression.element.Parentheses;
import com.rw.tool.util.expression.element.RightParentheses;
import com.rw.tool.util.expression.expression.Expression;
import com.rw.tool.util.string.StringScanner;

import java.util.Optional;

/**
 * 处理右括号的逻辑
 */
public class RightParenthesesElementParser extends ElementParser<RightParentheses> {
    public RightParenthesesElementParser() {
        super(RightParentheses.class);
    }

    @Override
    public Optional<ExpressionElement> handler(StringScanner scanner, int scale) {
        // 如果当前状态能接受右括号，则扫描右括号
        if (scanner.hasNext(Expression.RIGHT_PARENTHESES_REGEX)) {
            return Optional.of(Parentheses.of(scanner.next(Expression.RIGHT_PARENTHESES_REGEX)));
        }

        return Optional.empty();
    }
}
